Skip to content

Add unified market regime control plugin#5

Merged
Pigbibi merged 11 commits into
mainfrom
codex/market-regime-control-20260528
May 28, 2026
Merged

Add unified market regime control plugin#5
Pigbibi merged 11 commits into
mainfrom
codex/market-regime-control-20260528

Conversation

@Pigbibi

@Pigbibi Pigbibi commented May 28, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add deterministic market_regime_control facade plugin
  • unify crisis, macro risk, and TACO signals behind notification and position_control outputs
  • register runner support and example config

Validation

  • slowrun bash -lc ".venv/bin/python -m pytest tests/test_market_regime_control_plugin.py tests/test_strategy_plugin_runner.py -q"
  • .venv/bin/python -m ruff check touched plugin files

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 965a01faed

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

external_age_days = int((signal_date - external_as_of).days) if external_as_of is not None else None

kill_reasons: list[str] = []
if benchmark_symbol not in close.columns:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Block stale benchmark rows in the governor

When the input has a fresh row for any non-benchmark symbol (for example VIX/credit) but QQQ is missing or stale, resolve_signal_date(close, as_of) still selects that fresh matrix date and price_age_days stays within the limit. This column-only check does not catch that close[benchmark_symbol].loc[signal_date] is NaN, so the macro governor can emit no-action or an actionable VIX/credit route while its benchmark trend/drawdown inputs are absent or older than max_price_age_days.

Useful? React with 👍 / 👎.

@Pigbibi

Pigbibi commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

Historical tuning update (2026-05-28):\n\n- Re-ran real-product TQQQ history using the unified market_regime_control wrapper; wrapper reproduced legacy macro payload behavior exactly.\n- Best default candidate now uses realized_vol_threshold=0.30, requires VIX/credit/financial-stress confirmation before realized vol contributes to actionable_score, and sets delever_risk_asset_scalar=0.0.\n- Full sample 2010-02-12..2026-04-16 vs baseline: CAGR 25.77% (+1.03pp), max drawdown -34.77% (+0.29pp), Sharpe 1.006 (+0.039), Calmar 0.741 (+0.036).\n- Window check: 2022 rate-bear CAGR improves by +0.46pp vs baseline, Covid crash max drawdown improves by +4.15pp.\n- Verification: pytest tests/test_macro_risk_governor_plugin.py tests/test_market_regime_control_plugin.py tests/test_strategy_plugin_runner.py -q; ruff check src tests.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ed07ba91c0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}
)

vix_symbol = _first_available_symbol(close, vix_symbols)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Try later VIX aliases when the first column is stale

When the input contains multiple configured VIX aliases and the first alias column exists but has no usable value at the selected signal_date (for example VIX is stale/NaN while ^VIX has a fresh row), _first_available_symbol stops at the stale column and the code never checks the later aliases or external context. In that scenario vix_level/vix_spike remain None, so the governor can miss VIX watch/crisis evidence and understate the de-risking score even though a configured VIX source is available.

Useful? React with 👍 / 👎.

@Pigbibi

Pigbibi commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

Added a follow-up commit for versioned plugin contracts.

Highlights:

  • market_regime_control is now the default example/runtime facade for TQQQ and SOXL.
  • legacy crisis_response_shadow, macro_risk_governor, and taco_rebound_shadow remain runnable as deprecated compatibility mounts with market_regime_control as successor.
  • runner exports schema-version and successor metadata for contract checks.

Validation:

  • slowrun bash -lc ".venv/bin/python -m pytest tests/test_strategy_plugin_runner.py -q"
  • slowrun bash -lc ".venv/bin/ruff check src/quant_strategy_plugins/strategy_plugin_runner.py tests/test_strategy_plugin_runner.py"

@Pigbibi

Pigbibi commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

Update: broadened market_regime_control compatibility registration beyond TQQQ/SOXL to the weight-based rotation profiles now able to consume the unified artifact. README now states levered strategies consume direct position controls, while stock/ETF rotation strategies consume the same artifact through local risk-scaling policy and keep TACO notification-only.\n\nValidation: .venv/bin/python -m pytest tests/test_strategy_plugin_runner.py -q; ruff check touched runner/tests.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 886e20545e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

components,
strategy_policy=str(plugin_config.get("strategy_policy", "levered_growth_income_v1")).strip(),
taco_opportunity_size_scalar=float(plugin_config.get("taco_opportunity_size_scalar", 0.0) or 0.0),
as_of=str(plugin_config.get("as_of", "") or "").strip() or None,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve component signal dates in the facade

When as_of is a non-trading day or newer than the latest usable prices, each component builder rolls back to the resolved signal_date, but passing the original requested value here forces the facade's top-level as_of (and dated artifact name) to that later date. Downstream freshness checks that look only at the unified artifact can treat stale or weekend evidence as current even though the component payloads are dated earlier; let the arbiter infer from component as_of values instead of overriding it with the request.

Useful? React with 👍 / 👎.

@Pigbibi

Pigbibi commented May 28, 2026

Copy link
Copy Markdown
Contributor Author

更新:补充了 Market Regime Control 统一插件方案文档。

本次新增:

  • docs/market-regime-control-plan.zh-CN.md:记录统一 facade/arbiter 设计、组件职责、仲裁优先级、策略消费方式、版本管理和回测结论。
  • README.zh-CN.md:补充 market_regime_control 插件入口和设计说明链接。

方案摘要:

  • market_regime_control 作为统一 deterministic facade,对外只暴露 market_regime_control.v1
  • crisis_response_shadow 负责 true crisis 和泡沫脆弱性硬防守;macro_risk_governor 负责宏观降杠杆;taco_rebound_shadow 保持人工复核通知,不直接增加仓位。
  • 仲裁顺序是防守优先:crisis / macro risk-off veto TACO,macro delever veto TACO,watch-only 只通知。
  • AI audit 和 OSINT 字段没有交易权限,只能作为 shadow-only 证据或通知辅助。

验证:

  • git diff --check
  • .venv/bin/python -m pytest tests/test_market_regime_control_plugin.py tests/test_strategy_plugin_runner.py -q -> 28 passed

最新提交:e68b868 Document market regime control plan

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e68b8688d1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

or taco_route == "taco_fake_crisis"
)
)
taco_watch = bool(isinstance(taco, Mapping) and _normalized_action(taco) == ACTION_WATCH_ONLY and not _blocked(taco))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not turn unavailable TACO data into a watch route

When market_regime_control is mounted for a non-TQQQ strategy and the config omits taco_enabled or a matching attack_symbol, the runner still builds the TACO component by default; taco_rebound_shadow reports missing attack prices as suggested_action == "watch_only", not as blocked. This condition then promotes that unavailable component to taco_watch, so the unified artifact can emit a top-level watch notification every run even though there is no active TACO event or market-risk evidence. Gate this on real event/rebound context or treat TACO price-data suppression as unavailable for the facade.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5b2d774de6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

params["coed"] = str(end)
query = f"&{urlencode(params)}" if params else ""
frame = pd.read_csv(f"{FRED_GRAPH_URL.format(series_id=series_id)}{query}")
values = _clean_numeric_series(frame, date_column="observation_date", value_column=series_id)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Read the FRED graph CSV date column

When qsp-build-macro-external-context uses the default fetch_fred_series, FRED graph CSVs are parsed with a required observation_date column, but the public fredgraph.csv endpoint emits the date column as DATE. This makes every default FRED source raise during fetch and get recorded as status="error", so HY/IG OAS, financial stress, yield-curve, dollar, and funding fields are silently absent from the external context even though the CLI reports a completed output.

Useful? React with 👍 / 👎.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 75401d1f37

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

execution_controls["repository_allocation_mutation_allowed"] = False
if consumption_policy is not None:
execution_controls["notification_allowed"] = bool(consumption_policy.notification_allowed)
execution_controls["position_control_allowed"] = bool(consumption_policy.position_control_allowed)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Honor notification-only position policy

When market_regime_control runs under the market_regime_notification policy, this correctly records position_control_allowed = false in execution_controls, but the already-built payload["position_control"]["allowed"] remains true with live scalars from the facade. A consumer that reads the documented position_control block instead of the runner-specific execution_controls can therefore treat a notification-only artifact as an automated position-control signal; clear or disable that block whenever the consumption policy disallows position control.

Useful? React with 👍 / 👎.

@Pigbibi Pigbibi merged commit 2f95a29 into main May 28, 2026
1 check passed
@Pigbibi Pigbibi deleted the codex/market-regime-control-20260528 branch May 28, 2026 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant